/**
 * Created by q on 2017/4/13.
 */
import {CPT_ROOT} from '../config/config'
import {getStore, setStore, removeStore} from '../libs/util'
import {
  SET_HEADERNEED,
  SET_MENUNEED,
  SET_ISLOGINPAGE,
  SET_TOGGLE,
  SET_MOBILEMODE,
  SET_MENUCOLLAPSE,
  SET_POSTS,
  SET_MSG,
  SET_USER,
  SET_USERPROF,
  SET_USERINFO,
  SET_ROLE,
  SET_ORG,
  SET_ACCESSLIST,
  LOGOUT,
  SET_CAPTCHA,
  RESET_CAPTCHA,
  SET_TOKEN,
  SET_ROOMID,
  SET_SOCKET,
  SET_WSSTATUS,
  SET_ONLINEUSERS,
  SET_MSGARR,
} from './types'

export default {
  [SET_HEADERNEED] (state, value) {
    state.headerNeeded = value
  },
  [SET_MENUNEED] (state, value) {
    state.menuNeeded = value
  },
  [SET_ISLOGINPAGE] (state, value) {
    state.isLoginPage = value
  },
  [SET_TOGGLE] (state, value) {
    state.toggle = value
  },
  [SET_MOBILEMODE] (state, value) {
    state.mobileMode = value
  },
  [SET_MENUCOLLAPSE] (state, value) {
    state.menuCollapse = value
  },
  [SET_POSTS] (state, value) {
    state.posts = value
  },
  [SET_MSG] (state, value) {
    state.msg = value
  },
  [SET_TOKEN] (state, value) {
    state.token = value
    state.isLogin=true
  },
  [SET_USER](state, value){
    state.token = value.token
    state.userInfo = value.userInfo
    state.userprof = value.userprof
    state.role = value.role
    state.org = value.org
    state.dept=value.dept
    state.accesslist = value.accesslist
    state.isLogin = true
  },
  [SET_USERINFO] (state, value){
    state.userInfo = value
  },
  [SET_USERPROF] (state, value){
    state.userprof = value
  },
  [SET_ROLE](state, value){
    state.role = value
  },
  [SET_ORG](state, value){
    state.org = value
  },
  [SET_ACCESSLIST](state, value){
    state.accesslist = value
  },
  [LOGOUT] (state){
    state.token = null
    removeStore('token')
    state.userInfo = null
    state.isLogin = false
    state.headerNeeded=false
    state.menuNeeded=false
    state.userprof=null
    // state.role = null
    // state.org = null
    // state.accesslist = null
  },
  [SET_CAPTCHA](state, value){
    state.captchaUrl = CPT_ROOT + value.captchaUrl
    state.cptId = value.cptId
  },
  [RESET_CAPTCHA] (state){
    state.captchaUrl = state.captchaUrl + "?reload"
  },
  [SET_ROOMID](state, value){
    state.roomid = value
  },
  [SET_SOCKET](state, value){
    state.socket = value
  },
  [SET_WSSTATUS](state, value){
    state.wsStatus = value
  },
  [SET_ONLINEUSERS](state, value){
    state.onlineUsers = value
  },
  [SET_MSGARR](state, value){
    state.msgArr = value
  },
}

